using AlipayClass;
using ASP;
using HoWave.Common;
using HoWave.OnLinePay;
using HoWave.Web;
using HoWave.Web.Shop.Member;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Web.Profile;
using System.Web.SessionState;
public class User_Alipay_notify_url : Member, IRequiresSessionState
{
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		SortedDictionary<string, string> requestPost = this.GetRequestPost();
		AlipayConfig alipayConfig = new AlipayConfig();
		string partner = alipayConfig.Partner;
		string key = alipayConfig.Key;
		string input_charset = alipayConfig.Input_charset;
		string sign_type = alipayConfig.Sign_type;
		string transport = alipayConfig.Transport;
		LogBll logBll = new LogBll(this.conn);
		logBll.AddLog("Alipay", Fetch.CurrentUrl, "支付不成功！", DateTime.Now, "支付宝", Fetch.UserIp, Fetch.webDomain, 1, "支付宝");
		if (requestPost.Count > 0)
		{
			AlipayNotify alipayNotify = new AlipayNotify(requestPost, base.Request.Form["notify_id"], partner, key, input_charset, sign_type, transport);
			string responseTxt = alipayNotify.ResponseTxt;
			string a = base.Request.Form["sign"];
			string mysign = alipayNotify.Mysign;
			string text = string.Concat(new string[]
			{
				"responseTxt=",
				responseTxt,
				"\n notify_url_log:sign=",
				base.Request.Form["sign"],
				"&mysign=",
				mysign,
				"\n notify回来的参数：",
				alipayNotify.PreSignStr
			});
			if (responseTxt == "true" && a == mysign)
			{
				string text2 = base.Request.Form["trade_no"];
				string paymentNum = base.Request.Form["out_trade_no"];
				string text3 = base.Request.Form["total_fee"];
				string text4 = base.Request.Form["subject"];
				string text5 = base.Request.Form["body"];
				string text6 = base.Request.Form["buyer_email"];
				string text7 = base.Request.Form["trade_status"];
				OrderAction orderAction = new OrderAction(this.conn);
				if (base.Request.Form["trade_status"] == "TRADE_FINISHED" || base.Request.Form["trade_status"] == "TRADE_SUCCESS")
				{
					base.Response.Write("success");
					orderAction.PayReturn(paymentNum, "Pay");
				}
				AliPay aliPay = new AliPay();
				if (aliPay.is_WAIT_SELLER_SEND_GOODS)
				{
				}
			}
			else
			{
				base.Response.Write("fail");
			}
		}
		else
		{
			base.Response.Write("无通知参数");
		}
	}
	public SortedDictionary<string, string> GetRequestPost()
	{
		SortedDictionary<string, string> sortedDictionary = new SortedDictionary<string, string>();
		NameValueCollection form = base.Request.Form;
		string[] allKeys = form.AllKeys;
		for (int i = 0; i < allKeys.Length; i++)
		{
			sortedDictionary.Add(allKeys[i], base.Request.Form[allKeys[i]]);
		}
		return sortedDictionary;
	}
}
